<?php

namespace App\Http\Controllers\Admin;

use App\Models\User;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class UsersController extends Controller
{
    public function index(Request $request)
    {
        $q = $request->get('q');

        $users = User::query()->where('user_type',0)->inRandomOrder()->limit(10)->get();
        //return $users = User::query()->where('wechat_nickname', 'like', "%$q%")->where('user_type',0)->paginate(null, ['id', 'wechat_nickname as text']);

        $items = [];
        if(!empty($users))
        {
            foreach ($users as $v)
            {
                $items[] = ['id'=>$v->id,'text'=>$v->wechat_nickname];
            }
        }
        return $items;
    }
}
